﻿using System;
using System.Collections.Generic;

namespace JetBlack.Collections
{
    internal class ListQueue<T>
    {
        private List<T> queue;

        public ListQueue()
        {
            queue = new List<T>();
        }

        public ListQueue(IEnumerable<T> collection)
        {
            queue = new List<T>(collection);
        }

        public ListQueue(int capacity)
        {
            queue = new List<T>(capacity);
        }

        public void Clear()
        {
            queue.Clear();
        }

        public void Enqueue(T item)
        {
            queue.Add(item);
        }

        public T Dequeue()
        {
            T item = queue[0];
            queue.RemoveAt(0);
            return item;
        }

        public T[] DequeueAll()
        {
            T[] items = queue.ToArray();
            queue.Clear();
            return items;
        }

        public void Remove(T item)
        {
            queue.Remove(item);
        }

        public bool Contains(T item)
        {
            return queue.Contains(item);
        }

        public T Front
        {
            get { return queue[0]; }
            set { queue[0] = value; }
        }

        public T Back
        {
            get { return queue[queue.Count - 1]; }
            set { queue[queue.Count - 1] = value; }
        }

        public int Count
        {
            get { return queue.Count; }
        }

        public bool IsEmpty
        {
            get { return queue.Count == 0; }
        }
    }
}
